package com.atguigu.gulimall.product.web;

import com.atguigu.gulimall.product.entity.CategoryEntity;
import com.atguigu.gulimall.product.service.CategoryService;
import com.atguigu.gulimall.product.service.SkuInfoService;
import com.atguigu.gulimall.product.vo.Categlog2Vo;
import com.atguigu.gulimall.product.vo.SkuItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;
    @Autowired
    private SkuInfoService skuInfoService;

    @GetMapping({"/","/index.html"})
    public String index(Model model){
        //查询1级子菜单
        List<CategoryEntity> list = categoryService.selectLevel1();
        model.addAttribute("categorys",list);
        return "index";
    }

    @GetMapping("/item.html")
    public String item(Long skuId , Model model){
        //根据skuid查询sku信息
        SkuItemVo skuItemVo = skuInfoService.selectSpuID(skuId);
        model.addAttribute("skuItem",skuItemVo);
        return "item";
    }

    //index/json/catalog.json
    @ResponseBody
    @GetMapping("index/json/catalog.json")
    public Map<String, List<Categlog2Vo>> getCategory23(){
        Map<String, List<Categlog2Vo>> category23 = categoryService.getCategory23();
        return category23;
    }

}
